unit pricelist;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Sqlite3DS, FileUtil, CodyCtrls, Forms, Controls, Graphics,
  Dialogs, Buttons, ComCtrls, StdCtrls;

type

  { TfrmPriceList }

  TfrmPriceList = class(TForm)
    btnGenPriceList: TBitBtn;
    ProgressBar: TProgressBar;
    procedure btnGenPriceListClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  frmPriceList: TfrmPriceList;

implementation

{$R *.lfm}

uses main,fpspreadsheet;

{ TfrmPriceList }

procedure TfrmPriceList.btnGenPriceListClick(Sender: TObject);
var
  myWorkbook: TsWorkbook;
  myWorksheet: TsWorksheet;
  myCell: PCell;
  OUTPUT_FORMAT:TsSpreadsheetFormat;
  priceListN:Integer;
begin
  if FrmMain.SaveDialog.Execute then begin
    priceListN:=0;
    ProgressBar.Position:=priceListN;
    // Create the spreadsheet
    myWorkbook := TsWorkbook.Create;
    myWorksheet := myWorkbook.AddWorksheet('Прайс лист');
    myWorksheet.WriteUTF8Text(0,0,'Категорія');
    myWorksheet.WriteUTF8Text(0,1,'Роздрібна ціна');
    myWorksheet.WriteUTF8Text(0,2,'Дрібно оптова ціна');
    myWorksheet.WriteUTF8Text(0,3,'Крупно оптова ціна');
    myWorksheet.WriteUTF8Text(0,4,'Курс:');
    myWorksheet.WriteNumber(0,5,FrmMain.ExchangeRate);
    myWorksheet.WriteUTF8Text(1,4,'Дата:');
    myWorksheet.WriteUTF8Text(1,5,DateTimeToStr(Now));
    FrmMain.recordN :=1;
    FrmMain.rData(myWorksheet,'0');
    ProgressBar.Max:=FrmMain.recordN;
    myWorksheet.WriteUTF8Text(FrmMain.recordN+1,0,'Створено програмним забезпеченням http://emetemunoy.appspot.com/');
    // Save the spreadsheet to a file
    if FrmMain.SaveDialog.FilterIndex=1 then begin
      OUTPUT_FORMAT:=sfExcel8;
    end;
    if FrmMain.SaveDialog.FilterIndex=2 then begin
      OUTPUT_FORMAT:=sfOOXML;
    end;
    if FrmMain.SaveDialog.FilterIndex=3 then begin
      OUTPUT_FORMAT:=sfOpenDocument;
    end;
    myWorkbook.WriteToFile(FrmMain.SaveDialog.FileName,OUTPUT_FORMAT,True);
    myWorkbook.Free;
  end;
end;

end.

